/*
 * $Id: UsingInterruptToShutdownThread.java,v \$Revision$
 *
 * Last changed on: $Date: \$Date$
 * Last changed by: $Author: trsimoes $
 */
package org.eden.karb.sandbox;

/**
 * <description>
 *
 * @author trsimoes
 * @version $Revision:$
 */
public class UsingInterruptToShutdownThread extends Thread {

    public void run() {
        while (true) {
            System.out.print(". ");
            System.out.flush();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Thread.currentThread().interrupt(); // very important
                break;
            }
        }
        System.out.println("Shutting down thread");
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t = new UsingInterruptToShutdownThread();
        t.start();
        Thread.sleep(5000);
        t.interrupt();
        Thread.sleep(5000);
    }
}
